package org.kernely.stream;

import java.util.Dictionary;
import java.util.Hashtable;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventAdmin;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.osgi.service.http.HttpService;

public class Activator implements BundleActivator {

	/**
	 * Called when the bundle is STARTING
	 */
	public void start(BundleContext pBundleContext) throws Exception {

		// Register images
		ServiceReference sRef = pBundleContext.getServiceReference(HttpService.class.getName());
		if (sRef != null)
		{
			HttpService service = (HttpService) pBundleContext.getService(sRef);
			service.registerResources("/streambundle/images", "img", null);
		}

		// Choose topics to listen
		String[] topics = new String[] {
				"org/kernely/*"
		};
		Dictionary props = new Hashtable();
		props.put(EventConstants.EVENT_TOPIC, topics);
		
		// Register event handler
		pBundleContext.registerService(EventHandler.class.getName(), new StreamEventsHandler() , props);
	}

	/**
	 * Called when the Bundle is STOPPING
	 */
	public void stop(BundleContext arg0) throws Exception {

	}
}
